package com.gz.ezexcel.filter;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 * @author juice-gz
 * date 2022-01-05
 */
public class FreezeAndFilter implements SheetWriteHandler {


        public int colSplit = 0, rowSplit = 1, leftmostColumn = 0, topRow = 1;
        int startRow = 0; //第一行
        int lastRow =   1; // 结束行
        int startCol = 0; // 开始列
        int lastCol =  3;  //结束列
        @Override
        public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {

        }

        @Override
        public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
            Sheet sheet = writeSheetHolder.getSheet();
            sheet.createFreezePane(colSplit, rowSplit, leftmostColumn, topRow);
            sheet.setAutoFilter(new CellRangeAddress(startRow, lastRow, startCol, lastCol));
           //sheet.setAutoFilter(CellRangeAddress.valueOf(autoFilterRange));
        }

    public FreezeAndFilter(int startRow, int startCol, int lastCol) {
        this.startRow = startRow;
        this.startCol = startCol;
        this.lastCol = lastCol;
    }
    public FreezeAndFilter() {
    }
}
